{% extends "base.html" %}
{% block title %}申请单详情{% endblock %}
{% block head %}
    {{ super() }}
    <style>
        .title {
            background: #F5F5F5;
            padding: 10px;
            font-weight: bold;
        }
    </style>
{% endblock %}
{% block body %}
    <div class="contianer info-page">
        <div class="title weui-flex"><span class="weui-flex__item"> 申请单号：</span>
            <div class="btnGroup"></div>
        </div>
        <div class="weui-well">
            <div class="weui-flex onlyBottomBorder">
                <div class="weui-flex__item">
                    <div id="patientInfo"></div>
                    <div class="font12"><span class="text-disabled">门&nbsp;诊&nbsp;号：</span><span class="zyh"></span></div>
                    <div class="font12"><span class="text-disabled">床&nbsp;&nbsp;&nbsp;&nbsp;号：</span><span class="ch"></span></div>
                    <div class="font12"><span class="text-disabled">开单医生：</span><span class="kdys"></span></div>
                    <div class="font12"><span class="text-disabled">开单科室：</span><span class="kdks"></span></div>
                    <div class="font12"><span class="text-disabled">开单时间：</span><span class="kdsj"></span></div>
                </div>
                <div class="">
                    <div class="bcTarget" style="margin:0 auto;margin-top:10px;" barWidth="1"
                         barHeight="23">
                        <input type="hidden" value="">
                    </div>
                </div>
            </div>
            <div class="weui-flex font12 text-disabled">
                <div class="weui-flex__item">检查项目</div>
                <div class="weui-flex__item">部位</div>
                <div class="weui-flex__item" style="text-align: right">方法</div>
            </div>
            <div id="examList" class="onlyBottomBorder"></div>

        </div>
    </div>
{% endblock %}
{% block script %}
    {{ super() }}
    <script src="{{ url_for('page.send_static',filename='js/jquery-barcode.min.js') }}"></script>
    <script type="text/javascript">

        $(function () {
            var id = common.getQueryString("sheetID");
            var type = common.getQueryString("type");
            $.getJSON(navRoot + '/api/res/info', {"id": id}, function (data) {
                if (data["code"] == 200) {
                    var res = data["data"]["data"];
                    if (type == "0") {
                        {#document.title = "申请单详情";#}
                        $(".title>span").text("申请单号：" + res["SheetID"]);
                        $(".bcTarget").find("input").val(res["SheetID"]);
                    } else {
                        document.title = "申请单详情";
                        var cancelBtn = $("<button class=\"weui-btn weui-btn_mini\">取消预约</button>");
                        var changeBtn = $("<button class=\"weui-btn weui-btn_mini\">调整预约</button>");
                        $(".title>span").text("预约号：" + res["ScheduleID"]);
                        $(".bcTarget").find("input").val(res["SheetID"]);
                        //取消预约
                        cancelBtn.data("data", res);
                        cancelBtn.click(function () {
                            event.preventDefault();
                            event.stopPropagation();
                            var res_id = $(this).data("data")["SheetID"];
                            var self = $(this);
                            $.confirm({
                                title: '取消预约',
                                text: '是否取消此次预约！',
                                onOK: function () {
                                    //点击确认
                                    var params = {
                                        sheet_list: id,
                                        name: self.data("data")["PatientObj"]["name"]
                                    };
                                    $.post(navRoot + "/api/res/cancel", params, function (data) {
                                        location.href = navRoot + "?user_id=" + self.data("data")["PatientObj"]["hospitalizationID"];
                                    }, "json")
                                },
                                onCancel: function () {
                                }
                            });
                        });
                        //调整预约
                        changeBtn.data("data", res);
                        changeBtn.click(function () {
                            event.preventDefault();
                            event.stopPropagation();
                            var res_id = $(this).data("data")["SheetID"];
                            var name = $(this).data("data")["PatientObj"]["name"];
                            location.href = navRoot + "/reservation/datetime?id=" + res_id + "&name=" + name;
                        });
                        if (res["CurrentState"] == "1") {
                            $(".title>.btnGroup").append(cancelBtn);
                            $(".title>.btnGroup").append(changeBtn);
                        }
                    }
                    $("#patientInfo").html('<span class="font16 font-bold">' + res["PatientObj"]["name"] + '</span> <span class="font12">' + res["PatientObj"]["sex"] + ' ' + res["PatientObj"]["age"] + '</span>');

                    if (res["PatientObj"]["bedNumber"]) {
                        $(".zyh").closest("span").text("住 院 号");
                        $(".zyh").text(res["PatientObj"]["hospitalizationID"]);
                        $(".ch").text(res["PatientObj"]["bedNumber"]);
                    } else {
                        $(".ch").parent().hide();
                        $(".zyh").text(res["PatientObj"]["hospitalizationID"]);
                    }

                    $(".kdys").text(res["ReqSheetDoctor"]);
                    $(".kdks").text(res["BillingDeptName"]);
                    $(".kdsj").text(res["ReqSheetDateTime"]);

                    var examList = res["ExamList"];
                    var examCount = examList.length;
                    for (var i = 0; i < examCount; i++) {
                        var exam = $('<div class="weui-flex font12" style="padding:5px 0;">' +
                            '                <div class="weui-flex__item">' + (examCount > 1 ? i + 1 : '') + '[' + examList[i]['inspection'] + ']' + examList[i]['project'] + '</div>' +
                            '                <div class="weui-flex__item">' + examList[i]['bodyPart_second'] + '</div>' +
                            '                <div class="weui-flex__item" style="text-align: right">' + examList[i]['inspectionMethod'] + '</div>' +
                            '            </div>');
                        $("#examList").append(exam);
                    }

				<!-- $(".other").text((res["IsEmergent"] == 0 ? "不加急，" : "加急，") + (res["IsHepatorenalComplete"] == 0 ? "肝脏完整，" : "肝脏不全，") + (res["IsBedSide"] == 0 ? "不床旁" : "床旁")); -->

			<!-- $(".jczb").text(res["ExamList"][0]["prepare"] == "" ? "无" : res["ExamList"][0]["prepare"]); -->
			<!-- $(".bs").text(res["HistorySummary"] == "" ? "无" : res["HistorySummary"]); -->
			<!-- $(".lczd").text(res["ClinicalDiagnosis"] == "" ? "无" : res["ClinicalDiagnosis"]); -->
			<!-- $(".jcmd").text(res["ExamPurpose"] == "" ? "无" : res["ExamPurpose"]); -->
			<!-- $(".bljg").text(res["PathologicalResult"] == "" ? "无" : res["PathologicalResult"]); -->
			<!-- $(".gjsm").text(res["SpecialRemark"] == "" ? "无" : res["SpecialRemark"]); -->
			<!-- $(".yshjg").text(res["OperationResult"] == "" ? "无" : res["OperationResult"]); -->

                    $(".bcTarget").each(function (i, targetQRDiv) {
                        var $targetQRDiv = $(targetQRDiv);
                        if ($targetQRDiv && $targetQRDiv.children("input").val()) {
                            targetStr = $targetQRDiv.children("input").val();
                            targetWidth = $targetQRDiv.attr("barWidth");
                            if (!targetWidth) {
                                targetWidth = 20;
                            }
                            targetHeight = $targetQRDiv.attr("barHeight");
                            if (!targetHeight) {
                                targetHeight = 23;
                            }
                            targetType = $targetQRDiv.attr("datatype");
                            if (targetType == "qrcode") {
                                $targetQRDiv.qrcode({render: "canvas", width: 200, height: 200, text: targetStr});
                                $targetQRDiv.children("canvas").css('width', 200).css('height', 200);
                                $targetQRDiv.addClass("text-center");
                            } else {
                                var encode = "code128";
                                //if (8 === targetStr.length) encode = "ean8";
                                //else if (13 === targetStr.length) encode = "ean13";
                                $targetQRDiv.barcode(targetStr, encode, {
                                    barWidth: targetWidth,
                                    barHeight: targetHeight,
                                    showHRI: true,
                                    bgColor: "#fff"
                                });
                            }
                        }
                    })
                } else {
                    $.alert(data['errmsg']);
                }
            })
        })
    </script>
{% endblock %}
